package com.miz.bincalc;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class CalcActivity extends Activity{
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
        setContentView(R.layout.calc_layout);
		Button btn = (Button)findViewById(R.id.button1);
        btn.setOnClickListener(new OnClickListener(){
        	public void onClick(View arg){
        		EditText t1 = (EditText)findViewById(R.id.editText1), t2 = (EditText)findViewById(R.id.editText2);
        		int first = strToInt(t1.getText().toString()), second = strToInt(t2.getText().toString());
        		
        		/*if(first != 0)
        			ResultActivity.setNumbers(first);
        		else if(first != 0 && second != 0)
        			ResultActivity.setNumbers(first, second);
        		else
        			Toast.makeText(getApplicationContext(), "You must add first number!", Toast.LENGTH_SHORT).show();*/
        		
        		BinaryMath math = new BinaryMath(first, second);
        		ResultActivity.addText(math.convertToBinary(BinaryMath.CONVERT_BOTH) + "\n");
        	}
        });
	}
	
	public int strToInt(String str){
		int ret;
		try{
			ret = Integer.parseInt(str);
		}
		catch(Exception ex){
			ret = 0;
		}
		
		return ret;
	}
}
